<template>
    <div class="login_contain">
        <div class="login_box">
            <div class="login_avatar">
                <img src="../assets/login.jpeg">
            </div>
            <el-form :model="loginForm" status-icon :rules="loginRules" ref="loginForm" class="loginForm">
                <el-form-item prop="username">
                    <el-input    type="text" v-model="loginForm.username" autocomplete="off" placeholder="用户名"></el-input>
                </el-form-item>
                <el-form-item prop="password">
                    <el-input   type="password" v-model="loginForm.password" autocomplete="off" placeholder="密码"></el-input>
                </el-form-item>
                <el-form-item class="login_btn">
                    <el-button type="primary" @click="loginSubmit">登录</el-button>
                    <el-button @click="resetLogin">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>
<script>
    export default
    {
        name: "login",
    data(){
            return{
                loginForm:{
                    username:"",
                    password:"",
                },
                loginRules:{
                    username:[
                        {required: true, message: '用户名不能为空', trigger: 'blur'},
                        {min: 6, max: 12, message: '长度在 6 到 12 个字符', trigger: 'blur'}
                    ],
                    password:[
                        {required: true, message: '用户名不能为空', trigger: 'blur'},
                        {min: 6, max: 12, message: '长度在 6 到 12 个字符', trigger: 'blur'}
                    ]
                }
            }
        },
        methods:{
            resetLogin(){
                this.$refs.loginForm.resetFields();
            },
            loginSubmit(){
                var that =this;
                this.$http.post("http://localhost:8081/login",this.loginForm).then(function (response) {
                    if (response.data.code===1){
                        that.$message.success("登录成功")
                        that.$router.push("/home")
                    }else{
                        that.$message.error("登录失败")
                    }
                });
            }
        }
    }
</script>

<style scoped>
    .login_contain{
        width: 100%;
        height: 100%;
        background-color:#84869D;
    }
    .login_box{
        width: 430px;
        height: 300px;
        background-color: #fff;
        position: absolute;
        left: 50%;
        top:50%;
        transform: translate(-50%,-50%) ;
        border-radius: 3px;
    }
    .login_avatar{
        width: 130px;
        height: 130px;
        border-radius: 50%;
        border: 3px solid #fff;
        position: absolute;
        left: 50%;
        transform: translate(-50%,-50%);
        background-color: #fff;
        padding: 5px;
    }
    .login_avatar img{
        width: 100%;
        height: 100%;
        border-radius: 50%;
        background-color: #fff;
    }
    .loginForm{
        width: 100%;
        position: absolute;
        bottom: 0px;
        padding: 0px 20px;
        box-sizing: border-box;
    }
    .login_btn{
        display: flex;
        justify-content: flex-end;
    }
</style>